package function;

import java.util.ArrayList;
import controller.IOInput;
import controller.IOPrinter;
import dataObject.Brand;
import exception.UserSelectionOutOfRangeException;
import functionHelper.ProductLister;

public class ListSelectedBrand extends Function{
	private IOPrinter printer;
	private IOInput inputer;
	private ProductLister productLister;
	public ListSelectedBrand()
	{
		super("Search by Brand Name");//seek out what news updated of your favourite brand. or list all updatest.
		inputer = IOInput.getInputer();
		printer = IOPrinter.getPrinter();
		productLister = new ProductLister();
	}

	@Override
	public void perform(ArrayList<Brand> brandList) {
		printer.print("Please input the brand name of the product. If there are more than one brand name, separate by ','. Type 'All' to list all brand's product.");
		for(int i =0;i<brandList.size();i++)
		{
			printer.print((i+1)+". "+brandList.get(i).getName());
		}
		String userInput;
		boolean rightInput = false;
		while(rightInput==false)
		{
			try {
				userInput = inputer.getInputNext();
				productLister.listProduct(userInput, brandList);
				rightInput=true;
			} catch(UserSelectionOutOfRangeException e) {
				printer.print(e.getMessage());
			} catch (NumberFormatException e){
				printer.print("You must only input number");
			}
		}
	}
	
}
